<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-02 19:42:06
 * @LastEditTime: 2023-10-29 15:00:17
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Repositories;

use App\Models\ProProcessesInspectPack;

/**
 * Summary of ProProcessesInspectPackRepository
 * @property ProProcessesPassRepository $pass
 * @author sunkaiyuan
 */
class ProProcessesInspectPackRepository extends Repositories
    {
    public $relation_models = ["location", 'unit', 'swipor', 'checkmac', 'main' => ['company', 'material', 'order'], 'scrap' => ['defect']];

    public function boot(ProProcessesInspectPack $model)
        {
        $this->model = $model;
        }

    public function stockIn($pack)
        {
        $v        = $pack->main;
        $customer = $v->order?->main->customer_id;
        $pack->mergeWhere([
            'iscustomer'  => 1,
            'customer_id' => $customer,
            'company_id'  => $customer,
            'batchno'     => $v->batchno,
            'color_name'  => $v->color_name ?? "",
            'dyelot'      => $v->dyelot ?? "",
            'style'       => $pack->style ?? "",
            'material_id' => $v->material_id,
            'orderno'     => $v->cust_order ?? "",
            'custno'      => $v->open_card->custno,
            'unit_id'     => $pack->unit_id,
            'craft'       => $v->open_card->craft_remark,
            'sample_data' => $v->open_card->is_sample == 1 ? "小样" : "大货",
        ])->addStorage('检验入库', $v->code, $pack->quantity, $pack->auxiliary_quantity);
        }
    public function noStockIn($pack)
        {
        $pack->noaddStorage();
        }

    }